'use strict';

const model = require('../model');

async function getAll(ctx, next) {
    let data = await model.Role.findAll();
    ctx.render('roles.html', { data: data })
}
async function getById(ctx, next) {

}
async function addItem(ctx, next) {
    let obj = ctx.request.body;
    console.log(obj);
    await model.Role.create({
        rolename: obj.rolename,
        avatar: obj.avatar
    })

    ctx.body = '增加成功'
}
async function updateItem(ctx, next) {

}
async function delItem(ctx, next) {
    let id = ctx.request.params.id;
    await model.Role.destroy({
        where: {
            id: id
        }
    });

    ctx.body='删除成功555'
}

module.exports = {
    'get /roles': getAll,
    'get /roles/:id': getById,
    'post /roles': addItem,
    'put /roles/:id': updateItem,
    'delete /roles/:id': delItem,
}
